<template>
    <div>
        <!-- 门店资质 -->
        <el-form :model="ruleForm" label-width="120px">
            <el-form-item label="营业执照">
                <Upload :row="ruleForm.businessLicense" @OK="OKdata" @removeImg="removeImg"></Upload>
            </el-form-item>
            <el-form-item label="商品行业资质">
                <Upload :row="ruleForm.commodityIndustryQualification" @OK="OKdata1" @removeImg="removeImg1"></Upload>
            </el-form-item>
            <el-form-item label="补充资质(身份证)">
                <Upload :row="ruleForm.identityCard" @OK="OKdata2" @removeImg="removeImg2"></Upload>
            </el-form-item>
            <el-form-item label="补充资质(健康证)">
                <Upload :row="ruleForm.healthCertificate" @OK="OKdata3" @removeImg="removeImg3"></Upload>
            </el-form-item>
            <el-form-item label="补充资质(健康证)">
                <div>
                    <FileUpload :row="ruleForm.cooperationAgreement" @OK="OKdata4" @removeImg="removeImg4"></FileUpload>
                    <p style="margin: 0;">只能选择PDF格式的文件</p>
                </div>
            </el-form-item>
            <el-form-item label="过期时间">
                <el-date-picker v-model="ruleForm.expirationTime" type="date" placeholder="请选择" format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">保存</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
import Upload from './elUpload.vue'
import FileUpload from '@/components/fileUpload/index.vue'
import { reactive } from 'vue';
import { listStoresStoreQualifications, getStoreQualifications } from '@/api/merchantManagement.js'
import { ElMessage } from 'element-plus'
const props = defineProps({
    row: {
        type: Object,
        default: () => ({}), // 默认值为一个空对象
    },
})
const emit = defineEmits(['OKqualifications'])
const ruleForm = reactive({
    businessLicense: [],
    commodityIndustryQualification: [],
    identityCard: [],
    healthCertificate: [],
    cooperationAgreement: '',
    expirationTime: '',
    id: ''
})
const onSubmit = () => {
    listStoresStoreQualifications(ruleForm).then(res => {
        if (res.code == 200) {
            ElMessage({
                type: 'success',
                message: '保存成功',
            })
            emit('OKqualifications')
        }
    })
}
const getList = () => {
    getStoreQualifications(ruleForm.id).then(res => {
        if (res.code == 200) {
            ruleForm.cooperationAgreement = res.data.cooperationAgreement;
            if (res.data.businessLicense != '') {
                ruleForm.businessLicense = res.data.businessLicense.split(',');
            } else {
                ruleForm.businessLicense = []
            }
            if (res.data.commodityIndustryQualification != '') {
                ruleForm.commodityIndustryQualification = res.data.commodityIndustryQualification.split(',');
            } else {
                ruleForm.commodityIndustryQualification = []
            }
            if (res.data.identityCard != '') {
                ruleForm.identityCard = res.data.identityCard.split(',');
            } else {
                ruleForm.identityCard = []
            }
            if (res.data.healthCertificate != '') {
                ruleForm.healthCertificate = res.data.healthCertificate.split(',');
            } else {
                ruleForm.healthCertificate = []
            }
            ruleForm.expirationTime = res.data.expirationTime;
        }
    })
}
onMounted(() => {
    if (props.row) {
        ruleForm.id = props.row.id
    }
    getList()
})
const OKdata = (url) => {
    ruleForm.businessLicense.push(...url)
}
const removeImg = (item) => {
    ruleForm.businessLicense = item

}
const OKdata1 = (url) => {
    ruleForm.commodityIndustryQualification.push(...url)
}
const removeImg1 = (item) => {
    ruleForm.commodityIndustryQualification = item

}
const OKdata2 = (url) => {
    ruleForm.identityCard.push(...url)
}
const removeImg2 = (item) => {
    ruleForm.identityCard = item

}
const OKdata3 = (url) => {
    ruleForm.healthCertificate.push(...url)
}
const removeImg3 = (item) => {
    ruleForm.healthCertificate = item
}
const OKdata4 = (url) => {
    ruleForm.cooperationAgreement = url
}
const removeImg4 = (item) => {
    ruleForm.cooperationAgreement = item
}
</script>

<style lang="scss" scoped></style>